﻿@{
    ViewBag.Title = "SetParam";
}
@section scripts
{
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>   
}

<div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
    <table style="width:100%;">
        <tr>
            <td style="width:100%;">
                <a class="mini-button" id="save" name="save" iconCls="icon-save" onclick="saveData" plain="true">保存</a>
                 <span class="separator"></span>
                <a class="mini-button" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
            </td>
        </tr>
    </table>       
</div>


<div class="mini-fit" >
    <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" 
        borderStyle="border:0;" showPager = "false" showPageSize="false" showPageIndex="false" 
        url="GetParam" allowCellSelect="true" allowCellEdit="true" showColumnsMenu="true" fitColumns="false"  
        oncellcommitedit="onCellCommitEdit"  ondrawcell="DrawCell" oncellclick="cellclick">
        <div property="columns">
            <div type="checkboxcolumn" field="FMiniEdit" name="FMiniEdit" trueValue="1" falseValue="0" width="70" headerAlign="center">商户可修改</div>
            <div field="FMiniProgramName" name="FMiniProgramName" width="200" headerAlign="center" align="center">小程序标题
                <input property="editor" class="mini-textbox" />
            </div>
            <div name="FPic" width="100" headeralign="center" allowsort="true" style="font-size:12pt !important;" align="center">会员卡背景</div>
        </div>  
    </div>
</div>  

<script>
    mini.parse();
    var grid = mini.get("datagrid1");

    function FormShown() {  }

    load();

    function load() {
        grid.load({ json: parent.window.getSystemAppID() }, function (data) {
            if (data.data.length > 0 && data.data[0].FCorpClass == 0) {
                grid.hideColumn(0);
            }
            if (data.data.length > 0 && data.data[0].FCorpClass == 0 && data.data[0].FMiniEdit == 0) {
                //grid.allowCellEdit = false;
                //mini.get("save").setEnabled(false);
            }
        });
    }

    function saveData() {
        mini.get("save").setEnabled(false);
        var s = grid.getData();
        
        var mData = mini.encode(s);
        $.post("../WxMember/SaveParam", { json: mData, mSystemAppID: parent.window.getSystemAppID() }, function (data) {
            var ret = mini.decode(data);
            if (ret.status == 1) {
                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
            }
            else {
                mini.alert("异常:" + ret.error);
            }
            mini.get("save").setEnabled(true);
        });
    }

    function onCellCommitEdit(e) {
        mini.get("save").setEnabled(true); //编辑后保存按钮可用
    }

    function DrawCell(e) {
        if (e.column.header == '会员卡背景') {
            var PicUrl = e.row.FMiniBGK;
            if (PicUrl == '')
                PicUrl = '/content/images/MemberBGK/1.png';
            e.cellHtml = '<img src="' + PicUrl + '" width="50px" height="35px" />';
        }
    }

    function cellclick(e) {
        if (e.column.header != "会员卡背景") return;
        var s = grid.getData();        
        mini.open({
            url: "/WxMember/SetBGK",
            title: "会员卡背景", width: 700, height: 450,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = {
                    Index: s[0].FMiniBGKindex, Edit: s[0].FMiniEdit, FMiniBGK: s[0].FMiniBGK,
                    FMiniUploadBGK: s[0].FMiniUploadBGK, FCorpClass: s[0].FCorpClass, FName: s[0].FMiniProgramName
                };
                iframe.contentWindow.SetInfoData(data);
            },
            ondestroy: function (action) {
                load();
            }
        });
    }
</script>